# coding: utf-8

import time

from enum import Enum, unique

from common.constant import StatusEnum
from common.utils import ModelMaker


def get_timestamp():
    return int(time.time())


class DemandType(Enum):
    """
    created by chenhj at 2018/4/25

    """
    OUTDOOR_AD_SCREEN = 2
    DOOR_SCREEN = 1
    INFO_BULLETIN_SCREEN = 3
    STAGE_SCREEN = 4
    INDOOR_SCREEN = 5
    OTHER_SCREEN = 0


class DemandCate(Enum):
    """
    需求分类
    """
    INSTALL = 1
    MAINTAIN = 2
    RENT = 3


class DemandColor(Enum):
    """
    颜色
    """
    SINGLE_COLOR = 1
    DOUBLE_COLOR = 2
    FULL_COLOR = 3


class DemandStatus(Enum):
    """
    状态
    """
    DRAFT = 0
    PUBLISHING = 1
    UNCHECKED = 5
    DELAY = 6
    MASTER_DISPATCHING = 7
    BRONZE_MEDAL_DISCOUNT = 8
    DISPATCHING = 9
    ONGOING = 10
    ASSIGN = 11
    BID_DONE = 15
    SECOND_ONGOING = 20
    FREE_ONGOING = 30
    COMPETE_DONE = 100
    DONE = 200
    # DISCONTINUE = 400
    INVALID = 410


class FeedbackStatus(Enum):
    """
    create by ld_wu 2017-09-12
    反馈审核状态
    """
    REFUSE = 1
    PASS = 2
    PENDING = 3


class ParticStatus(Enum):
    """
    抢单参与状态
    """
    DRAFT = 0
    WAITING = 10
    NOT_CONTACT = 110
    BALANCE_NOT_ENOUGH = 120
    TIMEOUT_NOT_CONTACT = 130
    CALLING = 150
    SUCCEED = 200
    TALKED = 300


class FollowType(Enum):
    """
    created by chenhj at 2017/12/1

    """
    NA = 0
    LOCKED = 1
    KEEP = 2
    GIVE_UP = 3


class UserLevel(Enum):
    """
    用户等级
    """
    LEVEL_1 = 0
    # 铁牌
    LEVEL_2 = 10
    # 铜牌
    LEVEL_3 = 20


@unique
class UserLevelDisplay(StatusEnum):
    """
    用户等级
    """
    LEVEL_1 = (0, '无')
    LEVEL_2 = (10, '铁牌')
    LEVEL_3 = (20, '铜牌')


class EnterpriseLevel(Enum):
    """
    created by chenhj at 2018/5/24

    """
    # 铜牌
    LEVEL_3 = 20
    # 银牌
    LEVEL_4 = 30
    # 金牌
    LEVEL_5 = 40
    # 白金(地方合作伙伴)
    LEVEL_6 = 99


class DemandDisplay(object):

    cate_mapping = {
        1: '采购安装',
        2: '维修',
        3: '租赁'
    }

    color_mapping = {
        1: '单色',
        2: '双色',
        3: '全彩'
    }

    surr_mapping = {
        0: '其他场地',
        1: '户外',
        2: '室内',
        3: '半户外'
    }

    business_to_keys = {
        1: 'install',
        2: 'repair',
        3: 'rent',
    }

    malf_mapping = {
        0: '其他',
        1: '整屏或部分不亮',
        2: '出现两点暗点',
        3: '有色彩问题',
        4: '无法更换屏幕内容',
        5: '屏幕移位'
    }

    type_mapping = {
        0: '其它类型屏',
        1: '门头屏',
        2: '户外广告屏',
        3: '信息告示屏',
        4: '舞台用屏',
        5: '室内高清屏'
    }

    @property
    def type_display(self):
        """
        create by ld_wu 2018-01-25
        屏幕类型显示
        :return:
        """

        return self.type_mapping.get(self.type, '')

    @property
    def cate_display(self):
        """
        create by ld_wu 2018-01-25
        项目类型显示
        :return:
        """

        return self.cate_mapping.get(self.cate, '')

    @property
    def malf_display(self):
        if self.cate == DemandCate.MAINTAIN.value:
            return '、{}'.format(self.malf_mapping.get(self.malf))
        return ''

    @property
    def tag_key(self):
        return self.business_to_keys.get(self.cate, 'install')

    @property
    def color_display(self):
        """
        create by ld_wu 2018-01-25
        项目颜色显示
        :return:
        """

        return self.color_mapping.get(self.color, '')

    @property
    def surr_display(self):
        """
        create by ld_wu 2018-01-25
        :return:
        """
        return self.surr_mapping.get(self.surr, '')

    @property
    def span_display(self):
        return '{}'.format(self.span) if self.span else ''

    @property
    def size_display(self):
        return '{}㎡、'.format(self.size) if self.size else ''

    @property
    def new_msg_content(self):
        return '{city}、{size}{surr}{color}{span}{malf}'.format(
            city=self.city,
            size=self.size_display,
            surr=self.surr_display,
            color=self.color_display,
            span=self.span_display,
            malf=self.malf_display
        )


class ModelFactory(object):
    """
    create by ld_wu 2018-04-12
    模型工厂
    """
    base_mapping = dict(demand=DemandDisplay)

    def __getattr__(self, item):
        base = self.base_mapping.get(item)
        if base:
            model = ModelMaker.get_model(item, base)
        else:
            model = ModelMaker.get_model(item)
        setattr(self, item, model)
        return model


model_factory = ModelFactory()


class Feedback(StatusEnum):
    """
    create by ld_wu 2017-09-12
    反馈信息
    """
    NO_DEMAND = (1, '客户明确表示不需要')
    CANNOT_TOUCH = (2, '多次尝试，均联系不上客户')
    WRONG_NUMBER = (3, '客户号码有误')  # 暂时不用了
    MALICE = (4, '同行恶意询价')  # 暂时不用了

    CLIENT_NO_INTENTION = (5, '客户仅需报价，完全没有采购意向')
    PEERS_NOT_POINT_OUT = (6, '同行下单，但订单描述中未说明')
    BUDGET_NOT_MATCH = (7, '客户实际预算与订单描述不符')
    DESC_WRONG = (8, '订单信息严重有误导致交易无法进行')

    OTHER = (90, '其他')
    NO_REASON = (99, '无理由退款')